//
/*******************************************************************************
# File        : AnJiaBMKAnnotationView.m
# Project     : AnJiaApp
# Author      : Siter
# Created     : 2020/7/21
# Corporation : 成都好房通科技股份有限公司
# Description :
    
-------------------------------------------------------------------------------
# Date        : 2020/7/21
# Author      : Siter
# Notes       :
    
******************************************************************************/


#import "AnJiaBMKAnnotationView.h"
#import "GlobalConfig.h"


@implementation AnJiaBMKAnnotationView


- (id)initWithAnnotation:(id<BMKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
    if (self) {
        self.frame = CGRectZero;
        self.clipsToBounds = YES;
        self.iconView.clipsToBounds = YES;
        [self initSubViews];
        [self initTap];
    }
    return self;
}

- (void)showAnimation {
    [UIView animateWithDuration:0.3 animations:^{
        self.iconView.transform = CGAffineTransformIdentity;
    }];
}


-(void)initSubViews{
    [self addSubview:self.iconView];
    [self.iconView addSubview:self.titleLab];
    self.iconView.transform = CGAffineTransformMakeScale(0,0);
    [self showAnimation];
}

-(void)initTap{
    self.userInteractionEnabled = YES;
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionTapSelf:)];
    [self addGestureRecognizer:tap];
}

-(void)actionTapSelf:(UIView *)view{
    NSLog(@"-----------点击了");
//    [self clickSmallProntUpDataUI:!self.isSelect];
    if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectAnnotationView:)]) {
        [self.delegate didSelectAnnotationView:self];
    }
}

- (void)clickSmallProntUpDataUI:(BOOL)isSelect isHisSelected:(BOOL)isHisSelected {
    if (self.uiStyle == AnJiaMapAnnotationUiStyleSmall) {
        self.isSelect = isSelect;
        self.titleLab.textColor  = [UIColor whiteColor];
        if (isHisSelected) {
            self.iconView.image = [UIImage imageNamed:@"maphome_map_tag_his"];
            self.titleLab.textColor  = _appType == 1 ? [UIColor whiteColor] : [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
        } else {
            UIImage * nonIcon = [UIImage imageNamed:@"maphome_map_tag_none"];
            UIImage * selectIcon = [UIImage imageNamed:@"maphome_map_tag_select"];
            self.iconView.image = self.isSelect  ? selectIcon : nonIcon;
            self.titleLab.textColor  = [self titleColor];
        }
    }
}


#pragma mark public methods
/** 大区域标记渲染*/
- (void)setMaxProint:(NSString *)titleText{
    self.titleLab.numberOfLines = 0;
//    self.layer.cornerRadius = 35;
//    self.iconView.layer.cornerRadius = 35;
//    self.iconView.backgroundColor = RGBCOLOR(9,173,167);
    self.iconView.image = [UIImage imageNamed:@"椭圆4拷贝9"];
    self.frame = CGRectMake(0, 0, 96, 96);
    self.iconView.frame = CGRectMake(0, 0, 96, 96);
    self.titleLab.frame = CGRectMake(0, 0, 96, 96);
    self.titleLab.textColor  = [self titleColor];
    self.titleLab.text = titleText;
    self.iconView.transform = CGAffineTransformMakeScale(0,0);
    [self showAnimation];
}

- (void)setBackCorlor:(BOOL)isSelected {
    self.titleLab.numberOfLines = 0;
    //    self.layer.cornerRadius = 35;
    //    self.iconView.layer.cornerRadius = 35;
    //    self.iconView.backgroundColor = RGBCOLOR(9,173,167);
    self.iconView.image = isSelected ? [UIImage imageNamed:@"椭圆-选中"] : [UIImage imageNamed:@"椭圆4拷贝9"];
    self.frame = CGRectMake(0, 0, 96, 96);
    self.iconView.frame = CGRectMake(0, 0, 96, 96);
    self.titleLab.frame = CGRectMake(0, 0, 96, 96);
    self.titleLab.textColor = [self titleColor];
}

- (UIColor *)titleColor {
    if(_appType == 1){
        return [UIColor whiteColor];
    } else if (_appType == 2) {
        return [UIColor blackColor];
    } else if (_appType == 3) {
        return [UIColor whiteColor];
    } else {
        return [UIColor whiteColor];
    }
}

- (void)setAppType:(NSInteger)appType {
    _appType = appType;
}

- (void)setBuildBackCorlor:(BOOL)isSelected {
    
}

/** 小区域标记渲染*/
- (void)setSmallProint:(NSString *)titleText isSelect:(BOOL)isSelect isHisSelected:(BOOL)isHisSelected {
    self.isSelect = isSelect;
    self.layer.cornerRadius = 0;
    self.iconView.layer.cornerRadius = 0;
    self.titleLab.numberOfLines = 2;
    self.iconView.backgroundColor = UIColor.clearColor;
    UIImage * nonIcon = [UIImage imageNamed:@"maphome_map_tag_none"];
    UIImage * selectIcon = [UIImage imageNamed:@"maphome_map_tag_select"];
    CGRect viewFrame = isSelect ? CGRectMake(0, 0, selectIcon.size.width, selectIcon.size.height) : CGRectMake(0, 0, nonIcon.size.width, nonIcon.size.height);
    self.frame = viewFrame;
    self.iconView.frame = viewFrame;
    self.titleLab.frame = CGRectMake(10, 0, viewFrame.size.width -20, viewFrame.size.height);
    self.titleLab.textColor  = [self titleColor];
    
    if (isHisSelected) {
        self.iconView.image = [UIImage imageNamed:@"maphome_map_tag_his"];
    } else {
        self.iconView.image = isSelect ? selectIcon : nonIcon;
    }
    
    self.titleLab.text = titleText;
    [self showAnimation];
}

//阴影
- (void)addShadowWithColor:(UIColor *)theColor{
    self.iconView.layer.shadowColor = theColor.CGColor;
    self.iconView.layer.shadowOffset = CGSizeMake(0,0);
    self.iconView.layer.shadowOpacity = 0.08;
    self.iconView.layer.shadowRadius = 35;
    
    self.layer.shadowColor = theColor.CGColor;
    self.layer.shadowOffset = CGSizeMake(0,0);
    self.layer.shadowOpacity = 0.08;
    self.layer.shadowRadius = 35;
}

#pragma mark lazy
- (UIImageView *)iconView{
    if (!_iconView){
        _iconView = [[UIImageView alloc] init];
    }
    return _iconView;
}


- (UILabel *)titleLab{
    if (!_titleLab){
        _titleLab = [[UILabel alloc] init];
        _titleLab.textAlignment  = NSTextAlignmentCenter;
        _titleLab.font = [UIFont boldSystemFontOfSize:11];
        _titleLab.numberOfLines = 0;
    }
    return _titleLab;
}
@end
